home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / dosdir21.zip / DIRENT.H < prev    next >
C/C++ Source or Header  |  1994-06-22  |  4KB  |  156 lines

  1. /*  dirent.h
  2.  
  3.     Definitions for POSIX directory operations.
  4.  
  5. */
  6.  
  7. /*
  8.  *      C/C++ Run Time Library - Version 6.0
  9.  *
  10.  *      Copyright (c) 1991, 1993 by Borland International
  11.  *      All Rights Reserved.
  12.  *
  13.  * Modification History:
  14.  *  15-Feb-94  Borland    Original version.
  15.  *  22-Jun-94  J Mathews  Support VMS, non-Borland compilers,
  16.  *              and older Turbo C compilers;
  17.  *              Added d_namlen member to struct dirent.
  18.  */
  19.  
  20. #ifndef __DIRENT_H
  21. #define __DIRENT_H
  22.  
  23. /* Set up portability */
  24. #include "tailor.h"
  25.  
  26. #if defined(MSDOS)
  27. #  define DIR_CUR "."
  28. #  define DIR_PARENT ".."
  29. #  define DIR_END '\\'
  30. #  include <dos.h>
  31. #  if (defined(__GO32__) || defined(__EMX__))
  32. #    include <dirent.h>        /* use readdir() */
  33. #    ifdef __EMX__
  34. #      define GETDRIVE(d)    d = _getdrive()
  35. #      define SETDRIVE(d,n)    _setdrive(d, n)
  36. #    else
  37. #      define GETDRIVE(d)    _dos_getdrive(&d)
  38. #      define SETDRIVE(d,n)    _dos_setdrive(d, n)
  39. #    endif
  40. #  else /* !(__GO32__ || __EMX__) */
  41. #    define DEFINE_DIRENT
  42. #    ifdef __TURBOC__
  43. #      include <dir.h>
  44. #      define GETDRIVE(d)    d=getdisk()
  45. #      define SETDRIVE(d,n)    setdisk(d)
  46. #    else
  47. #      include <direct.h>
  48. #      define GETDRIVE(d)    _dos_getdrive(&d)
  49. #      define SETDRIVE(d,n)    _dos_setdrive(d, n)
  50. #    endif
  51. #  endif /* __GO32__ || __EMX__ */
  52. #elif defined(VMS)
  53. #  define DEFINE_DIRENT
  54. #  define DIR_CUR    "[]"
  55. #  define DIR_PARENT    "[-]"
  56. #  define DIR_END    ']'
  57. #  include <rms.h>
  58. #else /* ?unix */
  59. #  define DIR_CUR    "."
  60. #  define DIR_PARENT    ".."
  61. #  define DIR_END    '/'
  62. #  include <dirent.h>
  63. #endif
  64.  
  65. #if defined(VMS)
  66. #  define MAXNAMLEN    NAM$C_MAXRSS
  67. #  define MAXPATH    NAM$C_MAXRSS
  68. #elif defined(MSDOS)
  69. #  if defined(__OS2__)
  70. #    define MAXNAMLEN    256
  71. #  elif defined(__WIN32__) || defined(__DPMI32__)
  72. #    define MAXNAMLEN    260
  73. #  else
  74. #    define MAXNAMLEN    13
  75. #  endif /* ?MSDOS */
  76. #  ifdef __FLAT__
  77. #    define MAXPATH    260
  78. #  else
  79. #    define MAXPATH    80
  80. #  endif /* ?__FLAT__ */
  81. #else /* ?unix */
  82. #  ifndef MAXPATH
  83. #    define MAXPATH    255
  84. #  endif
  85. #  ifndef MAXNAMLEN
  86. #    define MAXNAMLEN    255
  87. #  endif
  88. #endif /* ?VMS */
  89.  
  90. #ifdef DEFINE_DIRENT /* do we need to define dirent structures/functions? */
  91.  
  92. /* dirent structure returned by readdir().  The first member (d_name)
  93.  * cannot be moved, because it is part of the DOS DTA structure used by
  94.  * findfirst() and findnext().
  95.  */
  96. struct dirent
  97. {
  98. #ifdef MSDOS
  99.     char           d_name[MAXNAMLEN];
  100. #else /* ?VMS */
  101.     char*          d_name;
  102. #endif
  103.     unsigned short d_namlen;
  104. };
  105.  
  106. #if defined(VMS)
  107.  
  108. /* DIR type returned by opendir().  The members of this structure
  109.  * must not be accessed by application programs.
  110.  */
  111. typedef struct {
  112.     struct FAB       _d_fab;        /* file access block */
  113.     struct NAM       _d_nam;        /* name block */
  114.     char       _d_esa[MAXNAMLEN];    /* extended string area */
  115.     char       _d_rsa[MAXNAMLEN];    /* resultant string area */
  116.     struct dirent  _d_dirent;        /* filename part of DTA */
  117.     char          *_d_dirname;        /* directory name */
  118.     unsigned char  _d_magic;        /* magic cookie for verifying handle */
  119. } DIR;
  120.  
  121. #elif defined(MSDOS)
  122.  
  123. /* DIR type returned by opendir().  The first two members cannot
  124.  * be separated, because they make up the DOS DTA structure used
  125.  * by findfirst() and findnext().
  126.  */
  127. typedef struct
  128. {
  129.     char           _d_reserved[30];    /* reserved part of DTA */
  130.     struct dirent  _d_dirent;        /* filename part of DTA */
  131.     char          *_d_dirname;        /* directory name */
  132.     char           _d_first;        /* first file flag */
  133.     unsigned char  _d_magic;        /* magic cookie for verifying handle */
  134. } DIR;
  135.  
  136. #endif  /* ?VMS */
  137.  
  138. #ifdef __cplusplus
  139. extern "C" {
  140. #endif
  141.  
  142. /* Prototypes.
  143.  */
  144. DIR                 * opendir   OF((const char *dirname));
  145. struct dirent       * readdir   OF((DIR *dir));
  146. int                   closedir  OF((DIR *dir));
  147. void                  rewinddir OF((DIR *dir));
  148.  
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152.  
  153. #endif /* DEFINE_DIRENT */
  154.  
  155. #endif  /* __DIRENT_H */
  156.